const { ccclass, property } = cc._decorator;

@ccclass
export default class Helloworld extends cc.Component {

    @property(cc.Sprite)
    roundRectAngle: cc.Sprite = null;

    @property(cc.Label)
    angleSizeText: cc.Label = null;
    @property(cc.Slider)
    slider:cc.Slider = null;

    start() {
        this.slider.progress = 0.5;
        this._updateRoundAngle(0.5)
    }

    silderEvent(obj: cc.Slider) {
        let ratio = obj.progress;
        this._updateRoundAngle(ratio);

    }

    _updateRoundAngle(ratio: number) {
        this.angleSizeText.string = `${ratio.toFixed(2)}`
        let material = this.roundRectAngle.getMaterial(0);
        let width = this.roundRectAngle.spriteFrame.getOriginalSize().width;
        let height = this.roundRectAngle.spriteFrame.getOriginalSize().height;
        let minsize = Math.min(width, height);
        let radius = ratio * minsize * 0.5;
        // material.define("USE_ROUND", true);
        material.setProperty("round", new cc.Vec4(width, height, radius, 20));
    }
}
